﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ServiceProcess;
using System.Threading;
using System.Configuration;

namespace SendEmailCustomerService
{
    public class SendEmailService : ServiceBase
    {
        static private log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        Thread _Thread = null;
        public SendEmailService()
        {
            logger.Info("Begin Start!");
            _Thread = new Thread(new ThreadStart(Thread_Start));
            _Thread.Start();
            logger.Info("Service Start!");
        }

        public void Thread_Start()
        {
            while (true)
            {
                try
                {
                    try
                    {
                        //SearcForCrossDDRateHttpRequest();
                        Console.Write("test");
                    }
                    catch (Exception ex)
                    {
                        logger.Error(ex.Message);
                    }
                    int sleep = int.Parse(ConfigurationSettings.AppSettings["delaytime"]);
                    Thread.Sleep(sleep);
                }
                catch (Exception ex)
                {
                    logger.Error(ex.Message + " _ " + ex.StackTrace);
                }
            }
        }

        protected override void OnStart(string[] args)
        {
            logger.Info("Send Email Service is started\n");
            // TODO: Add code here to start your service.
        }

        protected override void OnStop()
        {
            logger.Info("Send Email Service is stop\n");
            // TODO: Add code here to perform any tear-down necessary to stop your service.
        }
    }
}
